-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: tokenized ECE do not show button when missing billing email #10019
fix: tokenized ECE do not show button when missing billing email #10019
Conversation
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
Size Change: 0 B Total Size: 1.39 MB ℹ️ View Unchanged
|
public function test_should_show_express_checkout_button_for_tokenized_ece_with_billing_email() { | ||
global $wp; | ||
global $wp_query; | ||
|
||
$this->mock_wcpay_account | ||
->method( 'is_stripe_connected' ) | ||
->willReturn( true ); | ||
WC_Payments::mode()->dev(); | ||
$_GET['pay_for_order'] = true; | ||
|
||
// Total is 100 USD, which is above both payment methods (Affirm and AfterPay) minimums. | ||
$order = WC_Helper_Order::create_order( 1, 100 ); | ||
$order_id = $order->get_id(); | ||
$wp->query_vars = [ 'order-pay' => strval( $order_id ) ]; | ||
$wp_query->query_vars = [ 'order-pay' => strval( $order_id ) ]; | ||
|
||
update_option( '_wcpay_feature_tokenized_cart_ece', '1' ); | ||
add_filter( 'woocommerce_is_checkout', '__return_true' ); | ||
|
||
$this->assertTrue( $this->system_under_test->should_show_express_checkout_button() ); | ||
|
||
remove_filter( 'woocommerce_is_checkout', '__return_true' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I attempted to create a test to negate the situation (e.g.: create a test to verify the button isn't rendered)
However, unsetting the billing email via either $order->set_billing_address( [ 'email' => '' ] )
or $order->set_billing_email('')
didn't work.
I thought of querying the DB directly, but with HPOS and non-HPOS alternatives, I didn't think it was maintainable.
So here we are 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried for a bit on this as well. The email really does not want to update. I'm getting strange results with the $order->save()
method. The same order ID is returned every time and no logs set within that method are coming through. So I'm with you on this one. Directly modifying the DB seems to be the only way to remove the email address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests well and LGTM! 🚢
public function test_should_show_express_checkout_button_for_tokenized_ece_with_billing_email() { | ||
global $wp; | ||
global $wp_query; | ||
|
||
$this->mock_wcpay_account | ||
->method( 'is_stripe_connected' ) | ||
->willReturn( true ); | ||
WC_Payments::mode()->dev(); | ||
$_GET['pay_for_order'] = true; | ||
|
||
// Total is 100 USD, which is above both payment methods (Affirm and AfterPay) minimums. | ||
$order = WC_Helper_Order::create_order( 1, 100 ); | ||
$order_id = $order->get_id(); | ||
$wp->query_vars = [ 'order-pay' => strval( $order_id ) ]; | ||
$wp_query->query_vars = [ 'order-pay' => strval( $order_id ) ]; | ||
|
||
update_option( '_wcpay_feature_tokenized_cart_ece', '1' ); | ||
add_filter( 'woocommerce_is_checkout', '__return_true' ); | ||
|
||
$this->assertTrue( $this->system_under_test->should_show_express_checkout_button() ); | ||
|
||
remove_filter( 'woocommerce_is_checkout', '__return_true' ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried for a bit on this as well. The email really does not want to update. I'm getting strange results with the $order->save()
method. The same order ID is returned every time and no logs set within that method are coming through. So I'm with you on this one. Directly modifying the DB seems to be the only way to remove the email address.
Fixes #
Changes proposed in this Pull Request
The Store API (which is used by the Tokenized ECE to process an order) doesn't allow to process an order if the billing email is not present.
This is logged in WC Core here: woocommerce/woocommerce#48540
However, while the discussion is happening, we'd like to quickly patch the tokenized ECE to provide a message in the merchant's logs when such thing happens.
At the same time, I'm disabling the ECE button if the billing email is not present, so that the customer doesn't see any errors when attempting to process the order.
Testing instructions
wp-admin
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge